package com.googlecode.jlsf.swing;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;

/**
 * Displays info about application
 */
public class AboutDialog extends JDialog implements ActionListener
{
	private static final long serialVersionUID = -6067150073057704181L;
	
	// dummy invisible frame provides setting a top-left icon of a dialog
	private static JFrame f;
	
	protected AboutDialog()
	{
		super(f = new JFrame(), ResourceManager.getString("about.name"), true);
		
		f.setIconImage(ResourceManager.getImage("info.png"));
		
		JPanel center = new JPanel(new BorderLayout(4, 4));
		
		this.getContentPane().setLayout(new BorderLayout());
		this.getContentPane().add(center);
	
		center.add(new JLabel(ResourceManager.getString("about.text")));
		
		center.setBorder(new CompoundBorder(
				new EmptyBorder(8, 8, 8, 8), new CompoundBorder(
						new EtchedBorder(), new EmptyBorder(4, 4, 4, 4))));
		
		JPanel bottom = new JPanel(new FlowLayout(FlowLayout.RIGHT, 4, 4));
		
		this.getContentPane().add(bottom, BorderLayout.SOUTH);
		
		JButton button = new JButton(ResourceManager.getString("button.ok"));
		button.addActionListener(this);
		bottom.add(button);
		
		this.pack();
		
        SwingUtils.moveToCenter(this);
	}

	public void actionPerformed(ActionEvent e)
	{
		this.setVisible(false);
	}

}
